package kr.ac.jejunu.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import kr.ac.jejunu.model.Book;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

public class Parser {
	private Connection connection;
	private int stateCode;
	private List<Book> books;
	
	public Parser(){
		setBooks(new ArrayList<Book>());
	}

	public void connect(String url) {
		setConnection(Jsoup.connect(url));
		try {
			setStateCode(getConnection().execute().statusCode());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void parse() {
		String bookTitle = "I need a girl";
		Book book = new Book(bookTitle);
		getBooks().add(book);
		
	}
	
	public Book getBookByIndex(int index) {
		return getBooks().get(index);
	}

	public void setStateCode(int stateCode) {
		this.stateCode = stateCode;
	}

	public int getStateCode() {
		return stateCode;
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	public Connection getConnection() {
		return connection;
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}

	public List<Book> getBooks() {
		return books;
	}
}
